# 要求 python 3.8+

if __name__ == '__main__':


    def get_full_name(first_name: str, last_name: str):
        full_name = first_name.title() + " " + last_name.title()
        return full_name

    print(get_full_name("john", "doe"))

    def get_name_with_age(name: str, age: int):
        name_with_age = name + " is this old: " + str(age)
        return name_with_age

    # 要求 python 3.8+ 简单的类型声明
    def get_items(item_a: str, item_b: int, item_c: float, item_d: bool, item_e: bytes):
        return item_a, item_b, item_c, item_d, item_d, item_e

    # 嵌套类型声明
    from typing import List

    def process_items(items: List[str]):
        for item in items:
            print(item)

    process_items(["a", "b", "c"])

    # 元组和集合
    from typing import Set, Tuple

    def process_items(items_t: Tuple[int, int, str], items_s: Set[bytes]):
        return items_t, items_s

    print(process_items((1, 2, "a"), {b"a", b"b"}))

    # 字典
    from typing import Dict

    def process_items(prices: Dict[str, float]):
        for item_name, item_price in prices.items():
            print(item_name)
            print(item_price)

    process_items({"a": 1.0, "b": 2.0})

    # 类
    class Person:
        def __init__(self, name: str):
            self.name = name

    def get_person_name(one_person: Person):
        return one_person.name

    # Pydantic 模型
    # pip install pydantic
    from datetime import datetime
    from pydantic import BaseModel

    class User(BaseModel):
        id: int
        name: str = "John Doe"
        signup_ts: datetime | None = None
        friends: list[int] = []

    external_data = {
        "id": "123",
        "signup_ts": "2017-06-01 12:22",
        "friends": [1, "2", b"3"],
    }
    user = User(**external_data)
    print(user)